import threading, time

# 并发控制（控制几个线程同时运行)
sem = threading.Semaphore(3)

def run():
    with sem:
        for i in range(5):
            print("%s--%d" % (threading.current_thread().name, i))
            time.sleep(1)


if __name__ == "__main__":
    for i in range(5):
        threading.Thread(target=run).start()